package com.sunricher.telinkblemeshlib.db;

import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;

import com.sunricher.telinkblemeshlib.models.UartDaliDevice;

import java.util.List;

@Dao
public interface UartDaliDeviceDao {

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insert(UartDaliDevice device);

    @Query("SELECT * FROM UartDaliDevice WHERE gateway_address = :gatewayAddress AND dali_address = :daliAddress")
    UartDaliDevice select(int daliAddress, int gatewayAddress);

    @Query("SELECT * FROM UartDaliDevice WHERE gateway_address = :gatewayAddress ORDER BY dali_address ASC")
    List<UartDaliDevice> selectAll(int gatewayAddress);

    @Query("DELETE FROM UartDaliDevice WHERE gateway_address = :gatewayAddress")
    void deleteAll(int gatewayAddress);

    @Query("DELETE FROM UartDaliDevice WHERE gateway_address = :gatewayAddress AND dali_address = :daliAddress")
    void delete(int daliAddress, int gatewayAddress);
}
